package com.nmgsr.ptmsapp.fragment;

import static com.nmgsr.ptmsapp.utils.ContantConfig.Base_Logo_URL;
import static com.nmgsr.ptmsapp.utils.ContantConfig.Base_URL;

import android.content.Intent;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nmgsr.beans.entity.PtmsUser;
import com.nmgsr.nettools.base.BaseFragment;
import com.nmgsr.ptmsapp.R;
import com.nmgsr.ptmsapp.activity.MainActivity;
import com.nmgsr.ptmsapp.activity.QRCodeScannerActivity;
import com.nmgsr.ptmsapp.activity.UpdateActivity;
import com.nmgsr.ptmsapp.config.PreferencesManager;
import com.squareup.picasso.Picasso;

public class MyFragment extends BaseFragment {
    private static final String TAG = "MyFragment";
    private ImageView user_image;
    private TextView tv_account,tv_nickName;
    private LinearLayout scanLayout,update_layout;
    @Override
    protected int getLayoutId() {
        return R.layout.my_fragment;
    }

    @Override
    public void initView() {
        user_image =rootView.findViewById(R.id.user_image);
        tv_account =rootView.findViewById(R.id.tv_account);
        tv_nickName =rootView.findViewById(R.id.tv_nickName);
        PtmsUser user = PreferencesManager.getPtmsUserInfo(mContext);
        if (user != null){
            tv_account.setText(user.getAccount());
            tv_nickName.setText(user.getNickName());
            Picasso.get().load(Base_Logo_URL+user.getSignature()).placeholder(R.drawable.error_data).error(R.drawable.error_data).into(user_image);
        }
        scanLayout =rootView.findViewById(R.id.scan_layout);
        update_layout =rootView.findViewById(R.id.update_layout);
        scanLayout.setOnClickListener(v -> {
            Intent intent = new Intent(mContext, QRCodeScannerActivity.class);
            startActivity(intent);
        });
        update_layout.setOnClickListener(v -> {
            Intent intent = new Intent(mContext, UpdateActivity.class);
            startActivity(intent);
        });

    }
}
